use crate::router_service::ping_pong::PingService;
use crate::router_service::ping_pong::PingServiceImpl;
use rpc::connection_manager::event::{IdleListener, IdleResultData, WriteData};
use rpc::{RpcContext, RpcResult};
use rpc_derive::service;

pub struct HeartIdleListener {
    write_idle_time: u64,
    read_idle_time: u64,
}

impl HeartIdleListener {
    fn new(write_idle_time: u64, read_idle_time: u64) -> Self {
        Self { write_idle_time, read_idle_time }
    }
}

impl IdleListener for HeartIdleListener {
    fn get_write_idle_time(&self) -> Option<u64> {
        Some(self.write_idle_time)
    }

    fn get_read_idle_time(&self) -> Option<u64> {
        Some(self.read_idle_time)
    }

    fn handle(&self, context: &RpcContext, idle_data: &IdleResultData) -> RpcResult<()> {
        println!("heart idle_data: {:?}", idle_data);
        let ping_service = service!(context.clone(), PingService);
        // let pong = ping_service.ping(RpcClientChannel::new(context.clone()), RpcPing)?;
        Ok(())
    }
}